<template>
  <div class="add_con_form tl" v-loading="loading">
    <el-dialog
      :close-on-click-modal="false"
      title="股东设置"
      :modal-append-to-body="false"
      :visible.sync="visible"
      :show="show"
      :before-close="closeDialog"
      @close="$emit('update:show', false)"
      class="tl size_13"
      width="800px"
    >
      <el-form
        :model="data"
        :rules="dataYZ"
        ref="data"
        class="mar_top"
        label-width="120px"
      >
        <el-form-item label="会员账号">
          <el-col :span="12">
            <el-input
              :rows="4"
              :placeholder="this.editUser"
              :disabled="true"
              clearable
            ></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="股东身份：">
          <el-col :span="18">
            <el-radio-group v-model="data.is_shareholder">
              <el-radio label="0">无</el-radio>
              <el-radio label="1">单店股东</el-radio>
              <el-radio label="2">全量股东</el-radio>
            </el-radio-group>
          </el-col>
        </el-form-item>

        <el-form-item label="所属店铺" v-if="data.is_shareholder == 1">
          <el-col :span="18">
            <el-input
              v-model="data.shareholder_extract_cn"
              size="small"
              disabled
            ></el-input>
          </el-col>
          <el-col :span="4" :offset="1">
            <el-button
              :loading="$store.state.isLoading"
              size="mini"
              type="primary"
              @click="xzshop('xz_extract')"
            >
              选择
            </el-button>
          </el-col>
        </el-form-item>

        <div class="mar_bottom_15">
          <span class="sizeColor size_13 sp_style"></span>
          <el-button
            :loading="$store.state.isLoading"
            size="medium"
            type="primary"
            @click.prevent="addUpdate('data')"
            >确定</el-button
          >
        </div>
      </el-form>
    </el-dialog>

    <keep-alive>
      <component
        :is="current"
        :show="show_xz"
        :isAll="false"
        showType="list"
        @sendShop="getSend"
        @isshow="getShow"
      ></component>
    </keep-alive>
  </div>
</template>

<script>
import xz_extract from "@/components/currency/xz_extract.vue";
export default {
  data() {
    return {
      value: "",
      data: {
        id: "",
        is_shareholder: "",
        shareholder_extract: "",
        shareholder_extract_cn: "",
      },
      loading: false,
      dataYZ: {},
      visible: this.show,
      current: "",
      show_xz: false,
    };
  },
  props: {
    show: Boolean,
    editId: String,
    editUser: String,
    is_supplier: String,
    clickNum: Number,
    row: Object,
  },
  components: { xz_extract },
  methods: {
    xzshop(str) {
      this.current = str;
      this.show_xz = true;
    },
    getShow(val) {
      this.show_xz = val;
    },
    getSend(row) {
      if (this.current == "xz_extract") {
        this.data.shareholder_extract_cn = row.title;
        this.data.shareholder_extract = row.id;
      }
    },
    closeDialog() {
      this.visible = false;
    },
    addUpdate(formName) {
      this.isDisable = true;
      setTimeout(() => {
        this.isDisable = false;
      }, 3000);
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var params = {};
          params["id"] = this.data.id;
          params["is_shareholder"] = this.data.is_shareholder;
          params["shareholder_extract"] = this.data.shareholder_extract;
          this.$api.getUser.user_shareholder_edit(params).then((res) => {
            if (res.data.code == 200 && res.data.result != null) {
              this.$emit("parent", "这里刷新父页面");
              this.$fnc.alertSuccess({ text: "编辑成功" }); //成功弹出框
              this.visible = false;
            } else {
              this.$fnc.alertError(res.data.result); //失败弹出框
            }
          });
        }
      });
    },
    onSuccess(pic) {
      this.data.shop_logo = pic;
    },
  },
  watch: {
    show() {
      this.visible = this.show;
    },
    clickNum(id) {
      // this.data = this.row;
      this.data.id = this.row.id;
      this.data.is_shareholder = this.row.is_shareholder;
      this.data.shareholder_extract = this.row.shareholder_extract;
      this.data.shareholder_extract_cn = this.row.shareholder_extract_cn;
    },
  },
  mounted() {},
  created() {},
};
</script>
